﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace monitoring_system.Views
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : UserControl
    {
        private List<Expander> expanders = new List<Expander>();
        public MainView()
        {
            InitializeComponent();
            expanders.Add(expander1);
            expanders.Add(expander2);
            expanders.Add(expander3);
            
        }

        private void TextBlock_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (App.Current.Resources.MergedDictionaries.Count > 0)
            {
                string light = "/Style/Light.xaml";
                string dark = "/Style/Dark.xaml";
                var path = App.Current.Resources.MergedDictionaries[0].Source.OriginalString;
                App.Current.Resources.MergedDictionaries.RemoveAt(0);
                path = path.Equals(light) ? dark : light;
                var source = new Uri(path, UriKind.RelativeOrAbsolute);
                var resource = (ResourceDictionary)Application.LoadComponent(source);
                resource.Source = source;
                App.Current.Resources.MergedDictionaries.Insert(0, resource);
            }
        }

        private void expander1_Expanded(object sender, RoutedEventArgs e)
        {
            Expander expander = (Expander)sender;
            if (sender == null)
            {
                return;
            }
            foreach (var item in expanders)
            {
                if (item.Name!= expander.Name)
                {
                    item.IsExpanded = false;
                }
            }
        }
    }
}
